/**
 * HTTP请求工具类
 */
class Http {
    /**
     * 基础请求URL
     * @type {string}
     */
    static baseURL = 'http://localhost:9595/api';

    /**
     * 发送POST请求
     * @param {string} url - 请求地址
     * @param {Object} data - 请求数据
     * @returns {Promise<any>}
     */
    static async post(url, data) {
        try {
            const response = await fetch(this.baseURL + url, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify(data)
            });

            if (!response.ok) {
                throw new Error('Network response was not ok');
            }

            return await response.json();
        } catch (error) {
            console.error('Error:', error);
            throw error;
        }
    }

    /**
     * 发送GET请求
     * @param {string} url - 请求地址
     * @returns {Promise<any>}
     */
    static async get(url) {
        try {
            const response = await fetch(this.baseURL + url);

            if (!response.ok) {
                throw new Error('Network response was not ok');
            }

            return await response.json();
        } catch (error) {
            console.error('Error:', error);
            throw error;
        }
    }
} 